import {FileInfo} from "@shared/models/FileInfo";
import {Injectable} from "@angular/core";
@Injectable({
  providedIn: 'root',
})
export class ClipboardService{
  private _files: Array<FileInfo>=[];
  // 默认copy
  private _type: 'copy' | 'cut'='copy'

  get files(): Array<FileInfo> {
    return this._files;
  }

  get type(): "copy" | "cut" {
    return this._type;
  }

  copy(files:FileInfo[]){
    this._files=files;
    this._type='copy';
  }

  cut(files:FileInfo[]){
    this._files=files;
    this._type='cut';
  }
  clear(){
    this._files=[];
    this._type='copy';
  }

  canPaste(currentFile?: FileInfo) {
    if (!currentFile||this.files.length==0){
      return false;
    }
    return this.files.some(file=>file.parent!=currentFile.id)
  }
}
